package com.ljx.lambda.lambda01;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/3 9:54
 * @Version 1.0
 */
public class Test02 {
	public static void main(String[] args) {
		List<Student> arrayList = new ArrayList<>();
		arrayList.add(new Student("李吉星",18));
		arrayList.add(new Student("陈庆",8));
		arrayList.add(new Student("王俊凯",3));

		Comparator<Student> comparator=(o1,o2)->{
			return 	o1.getAge()-o2.getAge();
		};
		// 第一种当时传入lambda表达式
//		Collections.sort(arrayList,comparator);
		Collections.sort(arrayList,(o1,o2)->o1.getAge()-o2.getAge());
		System.out.println(arrayList);

	}
}

@Data
@NoArgsConstructor
class Student{
	private String name;
	private Integer age;

	public Student(String name, Integer age) {
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
}